import { defineConfig, globalIgnores } from "eslint/config";
import jsEslint from "@eslint/js";
import tsEslint, { parser } from "typescript-eslint";
import eslintPluginVue from "eslint-plugin-vue";
import globals from "globals";
// import eslintConfigPrettier from "eslint-config-prettier";
import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended";

export default defineConfig([
  globalIgnores(["**/node_modules/**", "**/dist/**", "**/coverage/**", "**/build/**", "**/tmp/**"]),
  {
    files: ["src/**/*.{js,ts,vue}"],
    extends: [
      jsEslint.configs.recommended,
      tsEslint.configs.recommended,
      eslintPluginVue.configs["flat/recommended"],
    ],
    languageOptions: {
      ecmaVersion: "latest",
      sourceType: "module",
      globals: globals.browser,
      parserOptions: {
        parser: tsEslint.parser,
        extraFileExtensions: [".vue"],
        projectService: true,
        tsConfigRootDir: import.meta.dirname,
        ecmaVersion: "latest",
        sourceType: "module",
      },
    },
  },
  /**
   * 这里 eslin-config-pretter 不需要了，eslint-plugin-prettier/recommended 里已经使用了 eslint-config-prettier；
   * 但是还是需要 安装 eslint-config-prettier， 因为 eslint-plugin-prettier 里把 eslint-config-prettier 作为宿主包使用的；
   **/
  // eslintConfigPrettier,
  // 不重新定义 prettier 规则是，直接加入这个 eslintPluginPrettierRecommended 配置对象即可
  eslintPluginPrettierRecommended,
  // 重新定义 prettier 规则
  {
    files: ["**/*.{js,ts,vue}"],
    rules: {
      // 这里定义的 prettier 规则，会覆盖 eslint-plugin-prettier/recommended 里的规则, 并且优先级高于 prettier 配置文件
      "prettier/prettier": [
        "error",
        {
          singleQuote: false,
        },
      ],
    },
  },
]);
